﻿Imports CupsApp.Data
Imports CupsApp.Service

Partial Public Class personal
    Inherits System.Web.UI.Page

    Public _data As PersonalInterview
    Public _service As CupsDomainService
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _service = New CupsDomainService
        _data = New PersonalInterview
        lvlMsg.Text = ""
        If Not IsPostBack Then
            If IsNothing(Request.QueryString("clientID")) Then
                lnkBackground.Enabled = False
                lnkHealthLegal.Enabled = False
                lnkHousing.Enabled = False
                lnkFollowUp.Enabled = False
                lnkStatus.Enabled = False
                lnkExit.Enabled = False

                CType(Master.FindControl("lnkNewClient"), LinkButton).Enabled = False
                CType(Master.FindControl("lnkNewClient"), LinkButton).Text = "> New Client/Family <"
            Else
                Client_ID.Value = Request.QueryString("clientID")
                _data = _service.GetPersonalInterview(Client_ID.Value)
                wwDataBinder1.DataBind()
            End If
        End If

       
    End Sub

#Region "Click Events"

    Protected Sub lnkBackground_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkBackground.Click
        If (String.IsNullOrEmpty(Client_ID.Value)) Then
            Return
        End If
        Response.Redirect(String.Format("background.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHealthLegal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHealthLegal.Click
        Response.Redirect(String.Format("health_legal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHousing_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHousing.Click
        Response.Redirect(String.Format("housing.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkFollowUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkFollowUp.Click
        Response.Redirect(String.Format("follow_up.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkStatus_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkStatus.Click
        Response.Redirect(String.Format("status.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkExit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkExit.Click
        Response.Redirect(String.Format("exit.aspx?clientID={0}", Client_ID.Value))
    End Sub

#End Region
 
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click

        Dim PhoneNumber As String = PhoneNumberTextBox.Text.Trim.Replace(" ", "")
        lvlMsg.ForeColor = Drawing.Color.Red
        If PhoneNumber <> "" Then
            If Not IsNumeric(PhoneNumber) Or PhoneNumber.Length > 11 Then
                lvlMsg.Text = "* Phone number is in an incorrect format, please follow the example!"
                Exit Sub
            End If
        End If

        wwDataBinder1.Unbind()

        _data.Phone = PhoneNumber

        If (String.IsNullOrEmpty(Client_ID.Value)) Then
            Client_ID.Value = _service.InsertPersonalInterview(_data)
            lnkBackground.Enabled = True
            lnkHealthLegal.Enabled = True
            lnkHousing.Enabled = True
            lnkFollowUp.Enabled = True
            lnkStatus.Enabled = True
            lnkExit.Enabled = True

        Else
            _service.UpdatePersonalInterview(Client_ID.Value, _data)
        End If

        lvlMsg.ForeColor = Drawing.Color.Green
        lvlMsg.Text = "* Personal information was saved successfully!"

    End Sub
End Class